package com.rc.saas.mini.service.tenant;

import com.rc.saas.mini.common.constant.WebConstant;
import com.rc.saas.mini.mapper.tenant.TenantOpenServiceMapper;
import com.rc.saas.mini.model.tenant.TenantOpenService;
import com.rc.saas.mini.model.tenant.TenantOpenServiceExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TenantOpenServiceServiceImpl implements TenantOpenServiceService {

    @Autowired
    private TenantOpenServiceMapper tenantOpenServiceMapper;

    @Override
    public TenantOpenServiceMapper getMapper() {
        return tenantOpenServiceMapper;
    }

    @Override
    public TenantOpenService selectByServiceTypeCode(String tenantCode, String serviceTypeCode) {
        TenantOpenServiceExample example = new TenantOpenServiceExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andServiceTypeCodeEqualTo(serviceTypeCode).andStatusEqualTo("0");
        List<TenantOpenService> tenantOpenServices = tenantOpenServiceMapper.selectByExample(example);
        if (tenantOpenServices != null && tenantOpenServices.size() > 0) {
            return tenantOpenServices.get(0);
        }
        return null;
    }

    @Override
    public boolean isServiceTypeCode(String tenantCode, String serviceTypeCode) {
        TenantOpenServiceExample example = new TenantOpenServiceExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andServiceTypeCodeEqualTo(serviceTypeCode).andStatusEqualTo(WebConstant.CON0);
        List<TenantOpenService> list = tenantOpenServiceMapper.selectByExample(example);
        return list.size() > 0 ? true : false;
    }
}
